Function.RegisterNamespace("System.EnvironmentStrategy");

System.EnvironmentStrategy.SpiderMonkey=function(){
    // IEnvironmentStrategy members
    this.Execute=function(command,parameters,voidOutput){
        throw new Error("System.EnvironmentStrategy.SpiderMonkey.Execute: Not Implemented. This method is abstract and must be overridden.");
    };

    this.Exit=function(errorCode){
        quit(errorCode);
    };

    this.GetNewLine=function(){
        throw new Error("System.EnvironmentStrategy.SpiderMonkey.GetNewLine: Not Implemented. This method is abstract and must be overridden.");
    };

    this.GetParameters=function(){
        var args={
            named:{},
            unnamed:[]
        };
        var params=Object.Global().arguments||Object.Global().scriptArgs;
        for(var i=0;i<params.length;i++){
            var param=String.Trim(params[i]);
            if(String.StartsWith(param,'/')&&String.Contains(param,':')){
                param=String.TrimStart(param,'/').split(':');
                args.named[param[0].toLowerCase()]=param.slice(1).join(':');
            }else args.unnamed.push(param);
        }
        return args;
    };
    
    this.GetWorkingDirectory=function(){
        throw new Error("System.EnvironmentStrategy.SpiderMonkey.GetWorkingDirectory: Not Implemented. This method is abstract and must be overridden.");
    };

    this.Write=function(message1,message2,messageN){
        putstr(Array.prototype.slice.call(arguments,0).join(''));
    };
    
    this.WriteError=function(message1,message2,messageN){
        (Object.Global().printErr||this.Write).call(this,Array.prototype.slice.call(arguments,0).join(''));
    }
    
    // IStrategySpecification members
    this.IsSatisfiedBy=function(candidate){
        return (typeof(system)!='undefined' && typeof(version)!='undefined' && typeof(snarf)!="undefined");
    };
};

System.EnvironmentStrategy.SpiderMonkey.Implement(System.EnvironmentStrategy.IEnvironmentStrategy,'System.EnvironmentStrategy.SpiderMonkey');
System.EnvironmentStrategy.SpiderMonkey.Implement(System.Script.Strategy.IStrategySpecification,'System.EnvironmentStrategy.SpiderMonkey');